/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUIUtilities;

import java.awt.Color;
import java.util.Random;

/**
 *
 * @author Heather
 */
public abstract class ColorUtilities
{

  public static Color lightenColor(Color c, int amount)
  {
    int red = c.getRed();
    int green = c.getGreen();
    int blue = c.getBlue();

    red += amount;
    green += amount;
    blue += amount;

    if (red > 255)
    {
      red = 255;
    }
    if (green > 255)
    {
      green = 255;
    }
    if (blue > 255)
    {
      blue = 255;
    }

    return new Color(red, green, blue, c.getAlpha());
  }

  public static Color lightenColorWithCap(Color c, int amount, int maxColorStrength)
  {
    int red = c.getRed();
    int green = c.getGreen();
    int blue = c.getBlue();

    red += amount;
    green += amount;
    blue += amount;

    if (red > maxColorStrength)
    {
      red = maxColorStrength;
    }
    if (green > maxColorStrength)
    {
      green = maxColorStrength;
    }
    if (blue > maxColorStrength)
    {
      blue = maxColorStrength;
    }

    return new Color(red, green, blue, c.getAlpha());
  }

  public static Color darkenColor(Color c, int amount)
  {
    int red = c.getRed();
    int green = c.getGreen();
    int blue = c.getBlue();

    red -= amount;
    green -= amount;
    blue -= amount;

    if (red < 0)
    {
      red = 0;
    }
    if (green < 0)
    {
      green = 0;
    }
    if (blue < 0)
    {
      blue = 0;
    }

    return new Color(red, green, blue, c.getAlpha());
  }

  public static Color getRandomColor()
  {
    Random randGen = new Random();

    int red = randGen.nextInt(255);
    int green = randGen.nextInt(255);
    int blue = randGen.nextInt(255);

    return new Color(red, green, blue);
  }

  public static Color getRandomColorWithConstraints(int minColorValue, int maxColorValue)
  {
    Random randGen = new Random();

    int red = randGen.nextInt(maxColorValue - minColorValue) + minColorValue;
    int green = randGen.nextInt(maxColorValue - minColorValue) + minColorValue;
    int blue = randGen.nextInt(maxColorValue - minColorValue) + minColorValue;

    System.out.println("min color: " + minColorValue);
    System.out.println("max color: " + maxColorValue);
    return new Color(red, green, blue);
  }

  public static Color getConflictColor(double altruism)
  {
    if (altruism == 0)
    {
      return new Color(0, 0, 255);
    }
    else
    {
      int magnitude = Math.abs((int) (altruism * 255));
      if (magnitude > 255) // in case altruisms too big
        magnitude = 255;

      //System.out.println("magnitude: " + magnitude);
      //System.out.println("altruism: " + altruism);
      if (altruism < 0)
      {
        return new Color(magnitude, 0, 255-magnitude);
      }
      else if (altruism > 0)
      {
        return new Color(0, magnitude, 255-magnitude);
      }
      else
        return Color.darkGray;
    }
  }
}
